#pragma once

#include "windows.h"
#include <string>
#include <list>

class CAdminSocket 
{
public:
	std::string m_Password;
	bool IsConnected();
	bool SendCommand(int nType);
	bool SendCommand(int nType, void *pData, int nDataLength);
	bool ParseRecvBuffer();
	virtual void Close();
	CAdminSocket();
	virtual ~CAdminSocket();
	void DoClose();
	bool IsClosed() { return m_bClosed; }

	static int GetLastError();

	virtual bool Connect(const char* lpszHostAddress, int nHostPort);
	virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
	virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0);
	bool ShutDown();

protected:
	struct t_data
	{
		unsigned char *pData;
		DWORD dwOffset;
		DWORD dwLength;
	};
	std::list<t_data> m_SendBuffer;

	bool m_bClosed;
	virtual void OnReceive(int nErrorCode);
	virtual void OnConnect(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	virtual void OnClose(int nErrorCode);

	unsigned char *m_pRecvBuffer;
	unsigned int m_nRecvBufferLen;
	unsigned int m_nRecvBufferPos;

	int m_nConnectionState;
};
